package com.wtf.dsp.admin.controller;


import com.wtf.dsp.admin.model.dto.MnsAddDTO;
import com.wtf.dsp.admin.model.dto.MnsDelDTO;
import com.wtf.dsp.admin.model.dto.MnsListDTO;
import com.wtf.dsp.admin.model.dto.MnsPageDTO;
import com.wtf.dsp.admin.model.vo.MnsVO;
import com.wtf.dsp.admin.service.MapperService;
import com.wtf.dsp.core.api.R;
import com.wtf.dsp.core.util.PageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * ClassName: DsMapperController
 * Description:
 * date: 2023/7/11 9:57
 *
 * @author linhuanyou
 * @version 1.0
 */
@Api(tags = "Mapper")
@RestController
@RequestMapping("/mapper")
public class MapperController {

    @Autowired
    private MapperService mapperService;

    @ApiOperation(value = "获取Mapper(分页)")
    @GetMapping("/page")
    public R<PageUtils> page(@Validated MnsPageDTO mnsPageDTO){
        PageUtils pageUtils = mapperService.page(mnsPageDTO);
        return R.ok(pageUtils);
    }

    @ApiOperation(value = "获取Mapper")
    @GetMapping("/list")
    public R list(@Validated MnsListDTO mnsListDTO){
        List<String> dmVOS = mapperService.list(mnsListDTO).stream().map(MnsVO::getMns).collect(Collectors.toList());
        return R.ok(dmVOS);
    }

    @ApiOperation(value = "新增Mapper")
    @PostMapping("/add")
    public R add(@RequestBody @Validated MnsAddDTO mnsAddDTO){
        int save = mapperService.add(mnsAddDTO);
        return R.ok(save);
    }

    @ApiOperation(value = "删除Mapper")
    @PostMapping("/del")
    public R remove(@RequestBody @Validated MnsDelDTO mnsDelDTO){
        int del = mapperService.remove(mnsDelDTO);
        return R.ok(del);
    }
}
